package com.xhqgov.manage.controller;

import com.xhqgov.manage.model.Dept;
import com.xhqgov.manage.util.DDUtil;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/dataSyn")
public class DataSynController extends BaseController{
    private static final Logger LOGGER = Logger.getLogger(DataSynController.class);

    @Resource
    private DDUtil ddUtil;
    /**
     * 跳转到数据同步页
     * @return
     */
    @RequestMapping("/index")
    public String index(){
        return "dataSyn/index";
    }

    /**
     * 同步数据包括员工、部门、角色
     * @return
     */
    @RequestMapping("/syn")
    @ResponseBody
    public Map<String,Object> syn(){
        /**
         * 同步数据代码
         */
        List<Dept> list = ddUtil.getDeptListFromDD();
        if(null !=list&&list.size()>0){
            for(Dept dept:list){
                System.out.println(dept.getId()+"-----------------"+dept.getName());
            }
        }else{
            return clientMap().failure().message("获取钉钉部门失败，请联系管理员").map();
        }

        return null;
    }

}
